<template>
	<view class="user-perfetion-page">
		<uni-forms ref="form" :modelValue="formData" :rules="rules" label-position="top" :label-width="200">
			<uni-forms-item label="手机号" required name="phone">
				<uni-easyinput type="text" v-model="formData.phone" placeholder="请输入手机号" />
			</uni-forms-item>	

			<div style='margin-top: 10rx;height: 150rpx;'></div>
			<div class="foot">
				<button class="submit" @click="submit" >提交</button>
			</div>
		</uni-forms>
	</view>
</template>

<script>
	import RboyUploadSfz from "@/components/Rboy-upload-sfz/Rboy-upload-sfz.vue"
	export default {
		data() {
			return {
				filetype:"",
				industrylist: [],
				areaindex: 0,
				addresslist: [],
				formData: {},
				doorplate: null,
				info: {},
				culture_text:'',
				face_text:'',
				rules: {
					// 对name字段进行必填验证
					phone: {
						rules: [{
							required: true,
							errorMessage: '请填写手机号',
						}, ],
					},
				},
				faceindex:0,
				cultureindex:0,
			};
		},
		components: {
			RboyUploadSfz,
		},
		created() {
			this.getlist();
			this.getdata();
		},
		onReady() {
			if (!uni.getStorageSync('token')) {
				uni.navigateTo({
					url: "/pages/login/login"
				})
			}

			// 需要在onReady中设置规则
			this.$refs.form.setRules(this.rules)
		},
		methods: {
			// 区域选则
			areaChange(e) {
				this.areaindex = e.detail.value
				this.formData.address = this.addresslist[this.areaindex].title
			},
			// 群众选择
			faceChange(e){
				this.faceindex = e.detail.value
				this.formData.face = this.faceindex
				this.face_text = this.facelist[this.faceindex];
			},
			getdata() {
				this.$H.get('/company/get').then(res => {
					if (res.status == 200) {
						this.formData = res.data.detail
						if(this.formData.nation == null) {
							this.formData.nation = "汉"
						}
						if(this.formData.nativeplace == null) {
							this.formData.nativeplace = "江西宜春"
						}
						this.culture_text = this.culturelist[this.formData.culture ];
						this.face_text = this.facelist[this.formData.face]
						this.doorplate = res.data.detail.doorplate
					}
				})
			},
			// 照片列表上传的记录
			select(e) {
				this.tempFilePaths = e.tempFilePaths
				this.filetype = 'license';
				this.upload(this.tempFilePaths, 0)
			},
			
			// 企业图册
			coverselect(e){
				this.tempFilePaths = e.tempFilePaths
				this.filetype = 'cover';
				this.upload(this.tempFilePaths, 0)
			},

			// 上传失败
			fail(e) {
				uni.showToast({
					title: '上传异常',
					icon: 'success'
				});
			},

			/*
			 *tempFilePaths上传附件的列表
			 *type 0照片 1附件
			 */
			upload(tempFilePaths,type) {
				if (this.tempFilePaths.length == 0) {
					return false
				}
				this.uploadFilePromise(tempFilePaths[0],type);
			},

			// 表单提交
			submit(form) {
				this.$refs.form.validate().then(res => {
					this.$H.post('/staff/add', {
						form: this.formData
					}).then(res => {
						if (res.status == 500) {
							uni.showToast({
								icon: "none",
								title: res.message
							})
						}
						if (res.status == 200) {
							uni.showToast({
								icon: "success",
								title: res.message
							})

							setTimeout(() => {
								uni.switchTab({
									url: '/pages/my/my',
								})
							}, 2000)
						} 
					})
				}).catch(err => {
					console.log('表单错误信息：', err);
				})
			},

		}
	}
</script>

<style scoped='scss' scoped>
	.user-perfetion-page {
		padding: 30px 30rpx;
		box-sizing: border-box;
	}

	.foot {
		position: fixed;
		bottom: 0rpx;
		left: 0px;
		width: 100%;
		height: 150rpx;
		background: #fff;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.submit {
		width: 600rpx;
		height: 92rpx;
		background: #17BF8B;
		border-radius: 46rpx;
		color: #fff;
	}


	.input {
		/* border-color: rgb(229, 229, 229); */
		background-color: rgb(255, 255, 255);
		border: 1px solid rgb(229, 229, 229);
		height: 70rpx;
		padding: 0px 10rpx;
		line-height: 70rpx;
		color: #666;
		border-radius: 10rpx;
		background: #f1f1f1;
	}

	/deep/ .uni-easyinput__content-input {
		background: #f1f1f1;
	}
</style>